package offer32;

import sun.reflect.generics.tree.Tree;

import java.util.ArrayList;
import java.util.List;

public class Solution2 {
    private List<List<Integer>> ret;
    public List<List<Integer>> levelOrder(TreeNode root){
        ret = new ArrayList<>();
        dfs(0,root);
        return  ret;
    }

    private void dfs(int depth,TreeNode node){
        if(node == null) return;
        if(depth == ret.size()){
            ret.add(new ArrayList<>());
        }
        ret.get(depth).add(node.val);
        dfs(depth+1,node.left);
        dfs(depth+1,node.right);
    }
}
